﻿#include "spinbox.h"




SpinBox::SpinBox (QWidget * parent) : QSpinBox (parent)
{
	m_timer = new QTimer (this);
	m_timer->setSingleShot (true);

	connect (this,
			 SIGNAL(valueChanged(int)),
			 this,
			 SLOT(onValueChanged(int)));

	connect (this,
			 SIGNAL(editingFinished()),
			 this,
			 SLOT(onEditingFinished()));

	connect (m_timer,
			 SIGNAL(timeout()),
			 this,
			 SLOT(onTimerTimeout()));

	setAccelerated (true);
}
//----------------------------------
void SpinBox::onValueChanged(const int newValue)
{
	m_value = newValue;
}
//--------------------------------------------------
void SpinBox::mouseReleaseEvent(QMouseEvent *event)
{
	emit changed (m_value);
	QSpinBox::mouseReleaseEvent (event);
}
//--------------------------------
void SpinBox::onEditingFinished()
{
	emit changed (value ());
}
//--------------------------------
void SpinBox::setValue(const int val)
{
	if (m_value == val) return;
	m_value = val;
	emit changed (val);
	QSpinBox::setValue (val);
}
//-------------------------------------------
void SpinBox::wheelEvent(QWheelEvent *event)
{
	m_timer->start (400);
	QSpinBox::wheelEvent (event);
}
//-----------------------------
void SpinBox::onTimerTimeout()
{
	emit changed (value ());
}



/**************************************************************/

DoubleSpinBox::DoubleSpinBox (QWidget * parent) : QDoubleSpinBox (parent)
{
	m_timer = new QTimer (this);
	m_timer->setSingleShot (true);

	connect (this,
			 SIGNAL(valueChanged(double)),
			 this,
			 SLOT(onValueChanged(double)));

	connect (this,
			 SIGNAL(editingFinished()),
			 this,
			 SLOT(onEditingFinished()));

	connect (m_timer,
			 SIGNAL(timeout()),
			 this,
			 SLOT(onTimerTimeout()));

	setAccelerated (true);
}
//-------------------------------------------------
void DoubleSpinBox::onValueChanged (const double newValue)
{
	m_value = newValue;
}
//--------------------------------------------------
void DoubleSpinBox::mouseReleaseEvent(QMouseEvent *event)
{
	emit changed (m_value);
	QDoubleSpinBox::mouseReleaseEvent (event);
}
//--------------------------------
void DoubleSpinBox::onEditingFinished()
{
	emit changed (value ());
}
//--------------------------------
void DoubleSpinBox::setValue(const double val)
{
	if (m_value == val) return;
	m_value = val;
	emit changed (val);
	QDoubleSpinBox::setValue (val);
}
//-------------------------------------------
void DoubleSpinBox::wheelEvent(QWheelEvent *event)
{
	m_timer->start (500);
	QDoubleSpinBox::wheelEvent (event);
}
//-----------------------------
void DoubleSpinBox::onTimerTimeout()
{
	emit changed (value ());
}

